import { BasicColumn, FormSchema } from '/@/components/Table';
import { h } from "vue"
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
import { AppIdEnum, NamespaceCodeEnum } from '/@/enums/iamEnum'
import { JsonPreview } from '/@/components/CodeEditor/index'
const { t } = useI18n('');

export const columns: BasicColumn[] = [
  {
    title: t('策略名称'),
    dataIndex: 'name',
    width: 200,
  },
  // {
  //   title: t('类型'),
  //   dataIndex: 'type',
  //   width: 100,
  // },
  {
    title: t('备注'),
    dataIndex: 'remark',
    width: 260,
    align: 'left',
  },
  {
    title: t('策略类型'),
    dataIndex: 'policyTypeName',
    width: 130,
  },
  {
    title: t('资源类型'),
    dataIndex: 'resourceTypeName',
    width: 130,
  },
  {
    title: t('创建时间'),
    dataIndex: 'createdAt',
    width: 150,
    align: 'center',
  },
  {
    title: t('被引用次数'),
    dataIndex: 'attachmentCount',
    width: 100,
  },
];


export const subjectPermPolicyColumns: BasicColumn[] = [
  {
    title: t('策略名称'),
    dataIndex: 'policy.name',
    width: 200,
    customRender: ({ record }) => {
      return render.renderTriggerEvent({ name: record.policy.name, data: record.policy }) 
    },
  },
  {
    title: t('主体类型'),
    dataIndex: 'subjectTypeName',
    width: 130,
  },
  {
    title: t('备注'),
    dataIndex: 'policy.remark',
    width: 200,
    align: 'left',
  },

  {
    title: t('策略类型'),
    dataIndex: 'policy.policyTypeName',
    width: 130,
  },
  {
    title: t('资源类型'),
    dataIndex: 'policy.resourceTypeName',
    width: 130,
  },
  {
    title: t('创建时间'),
    dataIndex: 'createdAt',
    width: 150,
    align: 'center',
  },
];


export const searchFormSchema: FormSchema[] = [
  {
    label: t('策略名称'),
    field: 'name',
    component: 'Input',
  },
  // {
  //   label: t('type'),
  //   field: 'type',
  //   component: 'Input',
  // },
];



export const inputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  
  {
    label: t('策略名称'),
    required: true,
    field: 'name',
    component: 'Input',
    colProps: { lg: 12, md: 12 },
    componentProps: {
      maxlength: 300,
    },

  },
  {
    label: t('备注'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
    },
    colProps: { lg: 12, md: 12 },
  },
];

export const menuInputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: t('策略名称'),
    required: true,
    field: 'name',
    component: 'Input',
    componentProps: {
      maxlength: 300,
    },

  },
  {
    label: t('备注'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
    }
  },
];

export const addFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'apiNamespaceCode',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'showPolicyType',
    component: 'RadioGroup',
    show: false,
  },
  {
    label: t('策略名称'),
    required: true,
    field: 'name',
    component: 'Input',
    componentProps: {
      maxlength: 300,
    },

  },
  {
    label: t("策略类型"),
    field: "policyType",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "PermPolicyType",
    },
    ifShow: ({ values }) => {
      return values.showPolicyType
    },
    required: true,
  },
  {
    label: t("资源类型"),
    field: "resourceType",
    component: "JDictSelectTag",
    componentProps: ({ formModel, formActionType }) => {
      return {
        appId: formModel.apiNamespaceCode == NamespaceCodeEnum.APP_GOVERN_HUB ? AppIdEnum.APP_GOVERN_HUB : null,
        dictType: "permPolicyResourceType",
        allowClear: true,
      }
    },
    required: true,
  },
  {
    label: t('备注'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
    }
  },
];


export const formDetailSchema: DescItem[] = [
  {
    label: t('策略名称'),
    field: 'name'
  },
  // {
  //   label: t('类型'),
  //   field: 'type'
  // },
  {
    label: t('资源类型'),
    field: 'resourceTypeName',
  },
  {
    label: t('策略类型'),
    field: 'policyTypeName'
  },
  {
    label: t('备注'),
    labelMinWidth: 40,
    field: 'remark'
  },
  {
    label: t('创建时间'),
    field: 'createdAt'
  },
  {
    label: t('更新时间'),
    field: 'updatedAt'
  },
  {
    label: t('创建者'),
    field: 'createdBy'
  },
  {
    label: t('更新者'),
    field: 'updatedBy'
  },
  {
    label: t('策略内容'),
    field: 'policyContent',
    render: (curVal, data) => {
      return h(JsonPreview, { data: curVal })
    }
  },
];
